package com.jt.controller;

import com.jt.annotation.RequiredLog;
import com.jt.pojo.Customer;
import com.jt.pojo.User;
import com.jt.service.CustomerService;
import com.jt.vo.PageResult;
import com.jt.vo.SysResult;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/customer")
public class CustomerController {
    @Autowired
    private CustomerService customerService;

    @GetMapping("/list")
    @RequiredLog
    public SysResult getCustomerList(PageResult pageResult){
        pageResult = customerService.getCustomerList(pageResult);
        return SysResult.success(pageResult);
    }

    /**
     * 状态更新
     */
    @PutMapping("/status/{id}/{status}")
    @RequiredLog
    public SysResult updateStatus(Customer customer){
        customerService.updateStatus(customer);
        return SysResult.success();
    }

    /**
     * 根据id删除
     */
    @DeleteMapping("/{id}")
    @RequiredLog
    public SysResult deleteCustomerById(@PathVariable Integer id){
        customerService.deleteCustomerById(id);
        return SysResult.success();
    }

    /**实现新增
     */
    @PostMapping("/addCustomer")
    @RequiredLog
    public SysResult addCustomer(@RequestBody Customer customer){
        customerService.addCustomer(customer);
        return SysResult.success();
    }

    /**根据ID查询数据库
     */
    @GetMapping("/{id}")
    @RequiredLog
    public SysResult getCustomerById(@PathVariable Integer id){
        Customer customer =  customerService.getCustomerById(id);
        return SysResult.success(customer);
    }

    /**实现修改操作
     */
    @PutMapping("/updateCustomer")
    @RequiredLog
    public SysResult updateCustomer(@RequestBody Customer customer){
        customerService.updateCustomer(customer);
        return SysResult.success(customer);
    }

//    @PostMapping("/addUser")
//    public SysResult saveUser(@RequestBody User user){
//
//        userService.saveUser(user);
//        return SysResult.success();
//    }



}
